{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['我', '爱', '北京', '天安门']\n"
     ]
    }
   ],
   "source": [
    "import pkuseg\n",
    "\n",
    "#! 普通示例\n",
    "seg = pkuseg.pkuseg()           # 以默认配置加载模型\n",
    "text = seg.cut('我爱北京天安门')  # 进行分词\n",
    "print(text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['我', '爱', '北京', '天安门']\n"
     ]
    }
   ],
   "source": [
    "#! 细分领域\n",
    "seg  = pkuseg.pkuseg(model_name='medicine')  # 程序会自动下载所对应的细领域模型\n",
    "text = seg.cut('我爱北京天安门')               # 进行分词\n",
    "print(text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('我', 'r'), ('爱', 'v'), ('北京', 'ns'), ('天安门', 'ns')]\n"
     ]
    }
   ],
   "source": [
    "#! 开启词性标注\n",
    "\n",
    "seg  = pkuseg.pkuseg(postag=True)  # 开启词性标注功能\n",
    "text = seg.cut('我爱北京天安门')     # 进行分词和词性标注\n",
    "print(text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 对input.txt的文件分词输出到output.txt中\n",
    "# 开20个进程\n",
    "pkuseg.test('input.txt', 'output.txt', nthread=20)     "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
